package com.example.casper.Experiment2024;

import static com.example.casper.Experiment2024.R.id.button_next;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class ImageViewActivity extends AppCompatActivity {

    private ImageView imageViewFunny;
    private final int[] imageIDArray = {R.drawable.funny_1, R.drawable.funny_2
            , R.drawable.funny_3, R.drawable.funny_4, R.drawable.funny_5
            , R.drawable.funny_6
    };
    private int imageIDArrayCurrentIndex;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_image_view);
        imageViewFunny = findViewById(R.id.image_view_funny);
        Button buttonPrevious = findViewById(R.id.button_previous), buttonNext = findViewById(button_next);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        buttonPrevious.setOnClickListener(new MyButtonClickListener());
        buttonNext.setOnClickListener(new MyButtonClickListener());

    }
    private class MyButtonClickListener implements View.OnClickListener {
        @Override
        public void onClick(View view) {
            if (button_next == view.getId()) {
                imageIDArrayCurrentIndex=(++imageIDArrayCurrentIndex)%imageIDArray.length;
            } else {
                imageIDArrayCurrentIndex=(--imageIDArrayCurrentIndex+imageIDArray.length)%imageIDArray.length;
            }
            imageViewFunny.setImageResource(imageIDArray[imageIDArrayCurrentIndex]);
        }
    }

}